package com.example.kakaotalk;

import android.content.Context;
import android.os.Bundle;
import android.support.v4.app.FragmentActivity;
import android.support.v4.app.FragmentTabHost;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.ImageView;
import android.widget.TabHost.OnTabChangeListener;
import android.widget.TextView;

public class MainActivity extends FragmentActivity {

	public static final String TAB_SPEC_FRIEND_LIST = "FriendsList";
	public static final String TAB_SPEC_CHATTING = "ChattingList";
	public static final String TAB_SPEC_RECOMMEND_FRIEND = "RecommendFriend";
	public static final String TAB_SPEC_MORE = "More";

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_main);
		
		initLayout();
	}
	
	private void initLayout(){		
		
		FragmentTabHost tabs = (FragmentTabHost) findViewById(android.R.id.tabhost);

		tabs.setup(this, getSupportFragmentManager(), R.id.realtabcontent);
		tabs.addTab(tabs.newTabSpec(TAB_SPEC_FRIEND_LIST).setIndicator(createTabIndicator(this,TAB_SPEC_FRIEND_LIST)), FriendsListFragment.class, null);
		tabs.addTab(tabs.newTabSpec(TAB_SPEC_CHATTING).setIndicator(createTabIndicator(this,TAB_SPEC_CHATTING)), ChattingListFragment.class, null);
		tabs.addTab(tabs.newTabSpec(TAB_SPEC_RECOMMEND_FRIEND).setIndicator(createTabIndicator(this,TAB_SPEC_RECOMMEND_FRIEND)), RecommendFriendFragment.class, null);
		tabs.addTab(tabs.newTabSpec(TAB_SPEC_MORE).setIndicator(createTabIndicator(this,TAB_SPEC_MORE)), MoreFragment.class, null);

		tabs.setCurrentTabByTag(TAB_SPEC_FRIEND_LIST);
		
	}

	private View createTabIndicator(Context context, String tabSpec) {
    	View tabIndicatorView = LayoutInflater.from(context).inflate(R.layout.tab_indicator, null);
    	TextView text = (TextView) tabIndicatorView.findViewById(R.id.tab_indicator_text);
    	
    	if (TAB_SPEC_FRIEND_LIST.equals(tabSpec)){
    		text.setCompoundDrawablesWithIntrinsicBounds(null, getResources().getDrawable(R.drawable.tab_friend_list_icon), null, null);
        	text.setText(getResources().getString(R.string.tab_indicator_friend_list));
    	}else if (TAB_SPEC_CHATTING.equals(tabSpec)){
    		text.setCompoundDrawablesWithIntrinsicBounds(null, getResources().getDrawable(R.drawable.tab_chatting_icon), null, null);
        	text.setText(getResources().getString(R.string.tab_indicator_chatting_list));
    	}else if (TAB_SPEC_RECOMMEND_FRIEND.equals(tabSpec)){
    		text.setCompoundDrawablesWithIntrinsicBounds(null, getResources().getDrawable(R.drawable.tab_recommend_friend_icon), null, null);
        	text.setText(getResources().getString(R.string.tab_indicator_recommend_friend_tab));    		
    	}else if (TAB_SPEC_MORE.equals(tabSpec)){
    		text.setCompoundDrawablesWithIntrinsicBounds(null, getResources().getDrawable(R.drawable.tab_more_icon), null, null);
        	text.setText(getResources().getString(R.string.tab_indicator_more_tab));    		
    	}
    	
    	return tabIndicatorView;
    }
	
}
